<template>
  <div>
  <div id='table-area'>
    <h2>校园活动审核</h2>
    <el-table
      :loading="listLoading"
      :data="list.slice((this.currentPage-1)*pagesize,currentPage*pagesize)"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        prop="actId"
        label="活动编号"
        width="100px"
      />

      <el-table-column
        align="center"
        prop="actTitle"
        label="活动名称"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="actType"
        label="活动级别"
        width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actType=='1'">学部级</span>
          <span v-if="scope.row.actType=='2'" style="color: blue;"><b>校级</b></span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="actMemberMax"
        label="活动人数"
        width="100px"
      />

      <el-table-column
        align="center"
        prop="actPrincipalName"
        label="活动负责人"
         width="120px"
      />

      <el-table-column
        align="center"
        prop="actPrincipalPhone"
        label="负责人电话"
        width="150px"
      />

      <el-table-column
        align="center"
        prop="actAddress"
        label="活动地点"
        width="300px"
      />

      <el-table-column
        align="center"
        prop="actMemberWay"
        label="录取方式"
         width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actMemberWay=='1'" >手动审核</span>
          <span v-if="scope.row.actMemberWay=='2'" >无需审核</span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="actStatus"
        label="活动状态"
         width="100px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.actStatus=='0'" >待审核</span>
          <span v-if="scope.row.actStatus=='1'" >报名中</span>
          <span v-if="scope.row.actStatus=='2'" >已截止</span>
          <span v-if="scope.row.actStatus=='3'" >已结束</span>
        </template>
      </el-table-column>


      <el-table-column align="center" label="操作" >
        <template slot-scope="Scope">
          <el-button type="primary" icon="el-icon-search" @click="getActivityInfo(Scope.row.actId)" size="mini">详细</el-button>
          <el-button type="warning" icon="el-icon-edit" @click="auditActivity(Scope.row.actId)" size="mini">审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div id="pages">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10]"
        :page-size="pagesize"
        layout="total, sizes,prev, pager, next"
        :total="list.length"
        prev-text="上一页"
        next-text="下一页"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
    <activity-info ref="info"  :actId='actId' :show='show'></activity-info>
  </div>
</template>

<script>
  import { getAllActivity } from '../../api/act.js'
  import { auditActivityByActId } from '../../api/act.js'
  import { getActivityByActId } from '../../api/act.js'
  import Info from '../../components/activity/info.vue'
  export default {
     name:'',
    //import引入的组件需要注入到对象中才能使用
    components: {
      'activity-info': Info
    },
    data() {
      //这里存放数据
      return {
        currentPage: 1, // 默认显示页面为1
        pagesize: 10, //    每页的数据条数
        list:[],
        act:[],
        listLoading:true,
        actId:'',
        show:false,
        dialogFormVisible:false,
        search:{},
        message:''
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      handleSizeChange (size) {
          this.pagesize = size
      },
          // 点击第几页
      handleCurrentChange (currentPage) {
          this.currentPage = currentPage
      },
      handleClick(row) {
          console.log(row)
      },
      getActivityInfo(actId){
            this.$refs.info.showInfo(actId)
      },
      auditActivity(actId){
        getActivityByActId(actId).then((data) => {
          this.act = data.obj
          if(data.obj.actStatus == '0'){
            auditActivityByActId(actId).then((data)=>{
              this.message = data.msg
              this.$message({
                    showClose: true,
                    message: '审核成功',
                    type: 'success'
              })
              console.log(this.message)
              location.reload()
            })
          }else{
            this.$message({
                    showClose: true,
                    message: '该活动已审核',
                    type: 'error'
                })
          }
        })
        
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      getAllActivity().then((data)=>{
          this.list=data.obj
          console.log(data.obj)
          this.listLoading=false
        })
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  }
</script>

<style>
  #table-area{
      margin-left: 10px;
      margin-right: 10px;
  }
</style>
